/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.core.runtime.event;

import com.farmcode.api.runtime.BaseEvent;
import com.farmcode.api.parser.ParserEngineAPI;
import com.farmcode.api.runtime.BaseResponse;
import com.farmcode.api.runtime.FARMCodeContext;
import com.farmcode.api.runtime.Response;
import com.farmcode.api.util.FARMCodeAPI;

/**
 *
 * @author oiprado
 */
public class CompileEvent extends BaseEvent<String> {

    @Override
    public Response<String> excecute(FARMCodeContext context) {
        try {

//      setParserEngineAPI(FarmcodeAPI.getInstance(ParserEngineAPI.COMPONENT_NAME));
//      Environment.getInstance().put(id, metadata);
            response = parserEngineAPI.parse(context);
//      StackTrace stackTrace = Environment.getInstance().getVariable(id).getTrace();
//      Iterator iterator = stackTrace.iterator();


//      while (iterator.hasNext()) {
//        System.out.println(((Trace) iterator.next()).getDescription());
//      }

//      return Environment.getInstance().getVariable(id).getTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
            response.getStackTrace().add(ex.getMessage());
        }
        return response;
    }
}
